<template>
<div class="layerRtb layerRtb-threecolumn layerRtb-right">
    <three-title :title="{name:'执行'}" :close="false">
        <span tag="i" class="rig_close fr" @click="$parent.$parent.clickFiveShow()"></span>
    </three-title>
    <div class="layerRtb-scroll thinScroll"  v-scrollHeight = "18">
        <div class="analyItem"  v-for="(item, index) of servicesList" :key="index" >
            <p class="analyItemTit tx-center">{{item.content | truncate(5)}}</p>
            <div class="analyItemCon">
                <div class="fixedBox">
                    <rx-viewer :images="item.data" style="position:relative" class="fl">
                        <div class="clearfix tx-center">
                            <div class="mr10">
                                <img :src="item.standard_imgUrl | smallImg(80, 80)">
                                <span class="standardStyle">标</span>
                            </div>
                        </div>
                    </rx-viewer>
                    <div class="fl" v-for="(item, index) of item.photoList" :key="index">
                        <rx-viewer :images="item" style="position:relative" :option={}>
                            <div class="clearfix tx-center">
                                <div class="mr10">
                                    <img :src="item | smallImg(80, 80)">
                                    <span class="standardStyle">现</span>
                                </div>
                            </div>
                        </rx-viewer>
                    </div>
                    <rx-upload
                        v-if="buttonIsShow"
                        class="fl"
                        :data="{id: item.id,index: index}" :init="{class: 2, mime: 1}"
                        :elStyle="{width:'90px', height: '80px'}"
                        @success="uploadPhoto">
                        <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                            <a href="javascript:">
                                <span type="file" value="" class="file"></span>
                                <em class="bgIcon file-ico"></em>
                            </a>
                        </div>
                    </rx-upload>
                </div>
                 <div>{{item.standard}}</div>
                 <span :class="['circlemark', item.photoList.length > 0 ? 'circlemark-lightGreen' : 'circlemark-lightRed']">{{item.photoList.length > 0 ? '完' : '未'}}</span>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem" style="height:210px">
            <p class="analyItemTit tx-center">处理</p>
            <div class="analyItemCon">
                <div class="clearfix">
                     <label class="fl pr8">验收报告</label>
                     <div class="fl" v-if="photoList.length === 0 && !buttonIsShow">
                        <img src="https://proj01.oss-cn-beijing.aliyuncs.com/common/1572060039EDheHQcxbw.png?x-oss-process=image/resize,m_fill,h_80,w_80,limit_0 | smallImg(80, 80)">
                    </div>
                    <div v-else>
                        <div class="fl" v-for="(item, index) of photoList" :key="index">
                            <rx-viewer :images="item" style="position:relative" :option={}>
                                <div class="clearfix tx-center">
                                    <div class="mr10">
                                        <img :src="item | smallImg(80, 80)">
                                    </div>
                                </div>
                            </rx-viewer>
                        </div>
                    </div>

                    <rx-upload
                        v-if="buttonIsShow"
                        class="fl"
                        :data="{}" :init="{class: 2, mime: 1}"
                        :elStyle="{width:'90px', height: '80px'}"
                        @success="joinPhoto">
                        <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                            <a href="javascript:">
                                <span type="file" value="" class="file"></span>
                                <em class="bgIcon file-ico"></em>
                            </a>
                        </div>
                    </rx-upload>
                </div>
                <div class="mt10 clearfix">
                    <label class="fl pr8">验收描述</label>
                    <span v-if="!buttonIsShow">{{content}}</span>
                    <textarea class="col-md-10" v-model="content" v-else></textarea>
                </div>
                <div class="mt10 clearfix">
                    <label class="fl pr8">验收结果</label>
                    <span v-if="!buttonIsShow">{{Number(radio) === 1 ? '合格' : '不合格'}}</span>
                    <div v-else class="fl">
                        <el-radio v-model="radio" label="1">合格</el-radio>
                        <el-radio v-model="radio" label="0">不合格</el-radio>
                    </div>
                </div>
                <div class="mt10 clearfix" v-if="radio !== '' && Number(radio) === 0">
                    <div class="col-md-6">
                        <label class="fl pr8">整改罚款</label>
                        <span v-if="!buttonIsShow">{{money}}</span>
                        <el-input v-model="money" placeholder="请输入罚款金额" size="mini" class="fl" type="number" style="width:150px" v-else></el-input>
                    </div>
                    <div class="col-md-6">
                        <label class="fl pr8">整改结束时间</label>
                        <span v-if="!buttonIsShow">{{$utils.format('yyyy-MM-dd', endtime)}}</span>
                        <el-date-picker
                            v-else
                            :picker-options="pickerBeginDateBefore"
                            class="fl"
                            v-model="endtime"
                            type="date"
                            placeholder="选择结束日期">
                        </el-date-picker>
                    </div>
                </div>
            </div>
        </div>
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
                <input type="button" class="uiBtn-normal uiBtn-blue" @click="uploadReportPhoto()" value="确定" v-if="buttonIsShow">
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { mapGetters, mapMutations } from 'vuex'
import { getSupervisionServicesItem, uploadPhoto, uploadReportPhoto } from '../../../../Resources/Api/nodeorder'
export default {
    props: ['type'],
    data () {
        return {
            pickerBeginDateBefore: {
                disabledDate: (time) => {
                    return time.getTime() < Date.now() - 8.64e7// 如果没有后面的-8.64e7就是不可以选择今天的
                }
            },
            checkImgLIst: [], // 验收图片
            buttonIsShow: false, // 是否显示按钮
            radio: '',
            value: 0,
            servicesList: [], // 服务项集合
            content: '', // 验收描述
            money: 0, // 整改罚款
            endtime: '', // 整改结束时间
            photoList: [], // 验收图片集合
            changeNumber: '545' // 滚动的高度
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo', 'twoToThreeInfo'])
    },
    created () {
        this.getSupervisionServicesItem()
        this.buttonType()
    },
    methods: {
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        // 按钮显示与隐藏
        buttonType () {
            if (this.userInfo.as_diquId === 39) {
                if (this.twoToThreeInfo.status === this.type) {
                    this.buttonIsShow = true
                } else {
                    this.buttonIsShow = false
                }
            } else {
                const userLevel = this.userInfo.as_level
                if (userLevel.length > 0) {
                    userLevel.forEach(ele => {
                        if (Number(ele) === 82 || Number(ele) === 83) {
                            if (this.twoToThreeInfo.status === this.type) {
                                this.buttonIsShow = true
                            } else {
                                this.buttonIsShow = false
                            }
                        } else if (Number(ele) === 47) {
                            if (Number(this.userInfo.as_cardNo) === Number(this.leftInfo.supervisor_userno)) {
                                if (this.twoToThreeInfo.status === this.type) {
                                    this.buttonIsShow = true
                                } else {
                                    this.buttonIsShow = false
                                }
                            } else {
                                this.buttonIsShow = false
                            }
                        } else {
                            this.buttonIsShow = false
                        }
                    })
                } else {
                    this.buttonIsShow = false
                }
            }
        },
        successUploadCheck (value) {
            this.checkImgLIst.push(value.src)
        },
        // 查询增值项
        getSupervisionServicesItem () {
            let parm = {
                orderCode: this.$route.query.code
            }
            // 接口订单数据
            getSupervisionServicesItem(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    this.servicesList = results.data.Body.supervisionServicesList
                    if (results.data.Body.report.qualified !== undefined) {
                        this.content = results.data.Body.report.AacceptanceContent
                        this.photoList = results.data.Body.report.photoList
                        this.radio = String(results.data.Body.report.qualified)
                        this.money = results.data.Body.report.money
                        this.endtime = results.data.Body.report.endTime
                    }
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 上传图片
        uploadPhoto (data) {
            let parm = {
                id: data.data.id,
                orderCode: this.$route.query.code,
                orderNo: this.leftInfo.orderno,
                userNo: this.userInfo.as_cardNo,
                userName: this.userInfo.as_fullName,
                photots: data.src
            }
            // 接口订单数据
            uploadPhoto(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    this.getSupervisionServicesItem()
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 上传验收报告
        uploadReportPhoto () {
            if (this.radio === '') {
                this.$message('请选择验收结果')
                return false
            }
            if (this.content === '') {
                this.$message('请输入内容')
                return false
            }
            if (Number(this.radio) === 0) {
                if (this.money === 0) {
                    this.$message('请填写罚款！！')
                    return false
                }
                if (this.endtime === '') {
                    this.$message('请填写整改时间！！')
                    return false
                }
            }
            let parm = {
                photots: this.photoList.length > 0 ? this.photoList.join(',') : this.photoList.lenth,
                orderCode: this.$route.query.code,
                orderNo: this.leftInfo.orderno,
                userNo: this.userInfo.as_cardNo,
                userName: this.userInfo.as_fullName,
                qualified: this.radio,
                money: this.money,
                endTime: this.endtime,
                acceptanceContent: this.content
            }
            // 上传验收报告
            uploadReportPhoto(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    this.setUpDatePlate()
                    this.$parent.$parent.clickFiveShow()
                }
            }).catch(error => {
                console.log(error)
            })
        },
        joinPhoto (param) {
            this.photoList.push(param.src)
        }
    },
    watch: {
        leftInfo () {
            this.getSupervisionServicesItem()
        }
    }
}
</script>
<style lang="">
    .fixedBox {
        display: flex;
        align-items: center;
    }
</style>
